<template>
  <div class="box-year">
    <div class="year-top">
      <p class="title">年度游客量</p>
      <p class="bg"></p>
    </div>
    <div class="year-bottom" ref="refYearLine"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
// 引入echarts
import 'echarts-liquidfill'
import * as echarts from 'echarts'
// 生命周期函数
onMounted(() => {
  createYearLine()
})
const refYearLine = ref()
const createYearLine = () => {
  const valueList1 = [116, 129, 135, 86, 73, 85, 73, 68, 92, 130, 245, 139]
  const valueList2 = [115, 111, 309, 206, 137, 128, 85, 94, 71, 106, 84, 93]
  const valueList3 = [94, 71, 106, 84, 93, 137, 29, 135, 86, 73, 85, 73]
  const dateList = Array.from({ length: 12 }, (v, k) => k + 1)
  const option = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        label: {
          show: true,
          formatter: '{value} 月',
        },
      },
    },
    legend: {
      data: ['2023年', '2022年', '2021年'],
      right: 0,
      top: 0,
      textStyle: {
        color: '#fff',
      },
    },
    xAxis: {
      data: dateList,
      axisLine: {
        lineStyle: {
          color: '#fff',
        },
      },
      boundaryGap: false,
    },

    yAxis: {
      splitLine: {
        //网格线
        show: false,
      },
      name: '人数',
      axisLine: {
        lineStyle: {
          color: '#fff',
        },
      },
      nameTextStyle: {
        align: 'right',
      },
    },

    grid: [
      {
        top: '15%',
        right: '4%',
        bottom: '10%',
      },
    ],
    series: [
      {
        name: '2023年',
        type: 'line',
        showSymbol: false,
        data: valueList1,
        areaStyle: {},
        smooth: true,
      },
      {
        name: '2022年',
        type: 'line',
        showSymbol: false,
        data: valueList2,
        areaStyle: {},
        smooth: true,
      },
      {
        name: '2021年',
        type: 'line',
        showSymbol: false,
        data: valueList3,
        areaStyle: {},
        smooth: true,
      },
    ],
  }
  const myChart = echarts.init(refYearLine.value, null, { renderer: 'svg' })
  myChart.setOption(option)
  return myChart
}
</script>

<style scoped lang="scss">
.box-year {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  margin: 20px 0px;
  .year-top {
    .title {
      color: #59b4e6;
      font-size: 20px;
    }

    .bg {
      width: 68px;
      height: 7px;
      background: url(../../images/dataScreen-title.png);
      margin-top: 20px;
    }
  }

  .year-bottom {
    height: calc(100% - 50px);
  }
}
</style>
